<template>
  <e-table
    ref="eTable"
    :tableData="evalData"
    :columns="evalColumns"
    :loading="loading"
    :pageObj="null"
    :maxHeight="500"
  >
    <el-table-column slot="upAndLow" align="center" label="奖惩上限-下限" width="120">
      <template
        slot-scope="scope"
      >{{ scope.row.rewardUpLimit ? scope.row.rewardUpLimit : '无上限' }} - {{ scope.row.rewardLowLimit ? scope.row.rewardLowLimit : '无下限' }}</template>
    </el-table-column>
    <el-table-column slot="rewardType" align="center" label="奖惩形式" width="80">
      <template slot-scope="scope">{{ scope.row.rewardType === 1 ? '分' : '钱' }}</template>
    </el-table-column>
    <el-table-column slot="evalTarget" align="center" label="考评对象" width="80">
      <template slot-scope="scope">{{ scope.row.evalTarget === 1 ? '科室' : '个人' }}</template>
    </el-table-column>
    <el-table-column slot="action" fixed="right" width="50" align="center">
      <template slot-scope="scope">
        <el-dropdown>
          <a class="el-dropdown-link">
            <i class="el-icon-menu"></i>
          </a>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="handleDelete(scope.row)">
              <a class="red">删除</a>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </template>
    </el-table-column>
  </e-table>
</template>

<script>
export default {
  props: {
    tableData: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      loading: false,
      evalData: [],
      evalColumns: [
        {
          label: '考评分类',
          prop: 'evalTypeId'
        },
        {
          label: '项目名称',
          prop: 'evalItemName',
          tooltip: true
        },
        {
          label: '项目内容',
          prop: 'evalItemContent',
          tooltip: true
        },
        {
          label: '考核标准',
          prop: 'standard',
          tooltip: true,
          width: '150px'
        },
        { slot: 'rewardType' },
        { slot: 'upAndLow' },
        {
          label: '奖惩标准',
          prop: 'rewardStandard',
          width: '80px'
        },
        { slot: 'evalTarget' },
        { slot: 'action' }
      ]
    }
  },
  watch: {
    tableData: {
      handler(n, o) {
        this.evalData = [...n]
      }
    }
  },
  methods: {
    handleDelete(row) {
      const _this = this
      this.$confirm({
        title: '删除操作',
        content: `您确定删除这条记录吗？`,
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        centered: true,
        async onOk() {
          // 调用删除接口，刷新表格数据
          const index = _this.fieldData.findIndex(v => v.xmId === row.xmId)
          _this.fieldData.splice(index, 1)
          openNotification('success', '删除成功')
          _this.$emit('tableUpdate', _this.fieldData)
        }
      })
    }
    // chooseEval(arr) {
    //   this.evalData = [...arr]
    // }
  },
  created() {
    console.log('tableData', this.tableData)

    this.evalData = [...this.tableData]
  }
}
</script>
